﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BestCode.Creds.Data.MapHelper;
using BestCode.Creds.Entities;
using NHibernate.Criterion;

namespace BestCode.Creds.Data
{
    public class TemplateDao : DaoBase<Template>, ITemplateDao
    {
        public IList<Template> GetByFilter(string filter)
        {
            return Session.QueryOver<Template>().Where(p => p.Code.IsLike(filter + "%")).List();
        }


        public Template GetAnverseFaceByEntity(int entityId)
        {
            return Session.QueryOver<EntityInfo>()
                .Where(p => p.Id == entityId)
                .Select(p => p.AnverseFace).List<Template>().FirstOrDefault();
        }

        public Template GetReverseFaceByEntity(int entityId)
        {
            return Session.QueryOver<EntityInfo>()
                   .Where(p => p.Id == entityId)
                   .Select(p => p.ReverseFace).List<Template>().FirstOrDefault();
        }
    }
}
